package com.example.big_event.controller;


import com.example.big_event.pojo.Article;
import com.example.big_event.pojo.PageBean;
import com.example.big_event.pojo.Result;
import com.example.big_event.service.ArticleService;
import com.example.big_event.utils.JwtUtil;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/article")
public class ArticleController {
    @Autowired
    private ArticleService articleService;



    //这个没有用了
    @GetMapping("/list")
    public Result<String> list(/*@RequestHeader(name = "Authorization") String token,HttpServletResponse response*/){

       /* //先验证token
        try {
            Map<String,Object> claims= JwtUtil.parseToken(token);

        }catch (Exception e){
            //http响应状态码为401
            response.setStatus(401);
            return  Result.error("未登录");
        }*/
        return Result.success("所有的文章数据....");


    }



    //添加文章
    @PostMapping
    public Result add(@RequestBody @Validated Article article){
        articleService.add(article);
        return Result.success();
    }


    //获取本人发布的文章列表
    @GetMapping
    public Result<PageBean<Article>>list(
            Integer pageNum,Integer pageSize,
            @RequestParam(required = false) Integer categoryId,
            @RequestParam(required = false) String state
    ){
        PageBean<Article>pb= articleService.list(pageNum,pageSize,categoryId,state);
        return Result.success(pb);
    }


    // 获取文章详情,根据文章的id，获取文章详情
    @GetMapping("/detail")
    public Result<Article> getDetail(Integer id){
        Article a= articleService.getDetail(id);
        return  Result.success(a);
    }

    //更新文章

    //删除文章
}
